<!-- START DEFAULT DATATABLE -->
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">管理报修分类</h3>
        <ul class="panel-controls">
            <li><a href="/admin/repair/editCategory.jspx?id=${id}"><i class="fa fa-plus"></i></a></li>
        </ul>
        <%--<button class="btn btn-default">再加一个</button>--%>
    </div>
    <div class="panel-body">
        <table class="table">
            <thead>
            <tr>
                <th>维修分类</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${categoryRepository.findByParentIdInTable(0)}" var="root">
                <tr class="item-comment comment-quote info" id="${root[0]}">
                    <td>${root[1]}</td>
                    <td>
                        <button class="btn btn-info btn-rounded btn-sm" title="查看人员" onclick="goViewPerson(${root[0]})">
                            <span class="fa fa-users"></span></button>
                        <button class="btn btn-info btn-rounded btn-sm" title="编辑分类" onclick="goEdit(${root[0]})"><span
                                class="fa fa-pencil"></span></button>
                        <button class="btn btn-danger btn-rounded btn-sm" title="删除分类"
                                onClick="delete_row(${root[0]});"><span class="fa fa-times"></span></button>
                    </td>
                </tr>
                <c:forEach items="${categoryRepository.findByParentIdInTable(root[0])}" var="child">
                    <tr class="item-comment comment-quote" id="${child[0]}">
                            <%--<td><label class="check"><input type="checkbox" class="icheckbox"></label></td>--%>
                        <td>${child[1]}</td>
                        <td>
                            <button class="btn btn-info btn-rounded btn-sm" title="编辑分类" onclick="goEdit(${child[0]})">
                                <span class="fa fa-pencil"></span></button>
                            <button class="btn btn-danger btn-rounded btn-sm" title="删除分类"
                                    onClick="delete_row(${child[0]});"><span class="fa fa-times"></span></button>
                        </td>
                    </tr>
                </c:forEach>
            </c:forEach>
            </tbody>
        </table>
    </div>
</div>
<!-- END DEFAULT DATATABLE -->

<!-- MESSAGE BOX-->
<div class="message-box message-box-warning animated fadeIn" id="mb-remove-row">
    <div class="mb-container">
        <div class="mb-middle">
            <div class="mb-title"><span class="fa fa-times"></span> <strong>删除该分类</strong> ?</div>
            <div class="mb-content">
                <p>你确定要删除这个分类吗？</p>
            </div>
            <div class="mb-footer">
                <div class="pull-right">
                    <button class="btn btn-info btn-lg mb-control-yes">确定</button>
                    <button class="btn btn-default btn-lg mb-control-close">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- END MESSAGE BOX-->

<!-- START SCRIPTS -->
<script>

    function delete_row(row) {
        var param = {};
        param.id = row;
        var box = $("#mb-remove-row");
        box.addClass("open");
        box.find(".mb-control-yes").on("click", function () {
            json("/admin/repair/delCategory.jspx", param, function (data) {
                if (data.code == 0) {
                    box.removeClass("open");
                    $("#" + row).hide("slow", function () {
                        $(this).remove();
                    });
                } else {
                    alert(data.description);
                }
            });
        });
    }
    function goEdit(o) {
        window.location.href = '/admin/repair/editCategory.jspx?categoryId=' + o;
    }
    function goViewPerson(o) {
        window.location.href = '/admin/repair/manageRepairPersons.jspa?categoryId=' + o;
    }

</script>
